package com.spring.mongodb;

import com.spring.mongodb.Redis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
@Path("/test")
public class Test {
    @Autowired
    Redis redis;

    @GET
    @Path("/redis/set/{key}/{value}")
    public boolean redis(@PathParam("key") String key, @PathParam("value") String value) {
        List<Map<String, Object>> list = new ArrayList<>();
        Map v = new HashMap();
        v.put(key, value);
        list.add(v);
        return redis.set(list);
    }

    @GET
    @Path("/redis/get/{key}")
    @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
    public List<String> redis(@PathParam("key") String key) {
        List<String> list = new ArrayList<>();
        list.add(key);
        return redis.get(list);
    }
}
